package com.dongfanggroup.report.controller;

import com.dongfanggroup.report.domain.ReportType;
import com.dongfanggroup.report.service.IReportTypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 故障类型Controller
 *
 * @author wangsr
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/ReportType")
public class ReportTypeController extends BaseController {
    @Autowired
    private IReportTypeService reportTypeService;

    /**
     * 查询故障类型列表
     */
    @RequiresPermissions("report:ReportType:list")
    @GetMapping("/list")
    public AjaxResult list(ReportType reportType) {
        List<ReportType> list = reportTypeService.selectReportTypeList(reportType);
        return AjaxResult.success(list);
    }

    /**
     * 导出故障类型列表
     */
    @RequiresPermissions("report:ReportType:export")
    @Log(title = "故障类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportType reportType) {
        List<ReportType> list = reportTypeService.selectReportTypeList(reportType);
        ExcelUtil<ReportType> util = new ExcelUtil<ReportType>(ReportType.class);
        util.exportExcel(response, list, "故障类型数据");
    }

    /**
     * 获取故障类型详细信息
     */
    @RequiresPermissions("report:ReportType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(reportTypeService.selectReportTypeById(id));
    }

    /**
     * 新增故障类型
     */
    @RequiresPermissions("report:ReportType:add")
    @Log(title = "故障类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportType reportType) {
        return toAjax(reportTypeService.insertReportType(reportType));
    }

    /**
     * 修改故障类型
     */
    @RequiresPermissions("report:ReportType:edit")
    @Log(title = "故障类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportType reportType) {
        return toAjax(reportTypeService.updateReportType(reportType));
    }

    /**
     * 删除故障类型
     */
    @RequiresPermissions("report:ReportType:remove")
    @Log(title = "故障类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(reportTypeService.deleteReportTypeByIds(ids));
    }


    /**
     * 查询故障类型列表
     */
    @GetMapping("/query/{pid}")
    public AjaxResult queryByPid(@PathVariable Integer pid) {
        List<ReportType> list = reportTypeService.selectReportTypeByPid(pid);
        return AjaxResult.success(list);
    }
}
